package com.morn.dict;

import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.UriMatcher;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.net.Uri;
import android.os.Environment;

import com.morn.dict.lib.MornDictLib;
import com.morn.dict.lib.util.Constants;

public class MornDictProvider extends ContentProvider {

	private MornDictLib mornDictLib;

	private static UriMatcher sUriMatcher;

	public static final String authority = "com.morn.dict.contentProvider";

	private static final int DICT_INFO = 1;
	
	SQLiteOpenHelper helper;

	static {
		sUriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
		sUriMatcher.addURI(authority, "dictInfo", DICT_INFO);

	}

	@Override
	public boolean onCreate() {
		mornDictLib = new MornDictLib();
		boolean sdCardExist = Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED);
		if (sdCardExist) {
			String dictDir = Environment.getExternalStorageDirectory().getAbsolutePath() + Constants.path;
			int initStatus = mornDictLib.init(dictDir);
			return initStatus == 1;
		}
		return false;
	}

	@Override
	public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
		switch (sUriMatcher.match(uri)) {
		case DICT_INFO:
			SQLiteDatabase db=helper.getReadableDatabase();
			
			break;

		}

		return null;
	}

	@Override
	public String getType(Uri uri) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Uri insert(Uri uri, ContentValues values) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int delete(Uri uri, String selection, String[] selectionArgs) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
		// TODO Auto-generated method stub
		return 0;
	}

}
